// 计算某一天时间
export function addByTransDate(dateParameter, num) {
  var translateDate = ''; var dateString = ''; var monthString = ''; var dayString = ''
  translateDate = dateParameter.replace('-', '/').replace('-', '/')
  var newDate = new Date(translateDate)
  newDate = newDate.valueOf()
  newDate = newDate - num * 24 * 60 * 60 * 1000 // 备注 如果是往前计算日期则为减号 否则为加号
  newDate = new Date(newDate)
  // 如果月份长度少于2，则前加 0 补位
  if ((newDate.getMonth() + 1).toString().length == 1) {
    monthString = 0 + '' + (newDate.getMonth() + 1).toString()
  } else {
    monthString = (newDate.getMonth() + 1).toString()
  }
  // 如果天数长度少于2，则前加 0 补位
  if (newDate.getDate().toString().length == 1) {
    dayString = 0 + '' + newDate.getDate().toString()
  } else {
    dayString = newDate.getDate().toString()
  }
  dateString = newDate.getFullYear() + '-' + monthString + '-' + dayString
  return dateString
}

export function getTime() { // 获取时间
  var date = new Date()

  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  if (month >= 1 && month <= 9) {
    month = '0' + month
  }
  if (day >= 0 && day <= 9) {
    day = '0' + day
  }
  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()

  // 这样写显示时间在1~9会挤占空间；所以要在1~9的数字前补零;
  if (hour < 10) {
    hour = '0' + hour
  }
  if (minute < 10) {
    minute = '0' + minute
  }
  if (second < 10) {
    second = '0' + second
  }
  var x = date.getDay()// 获取星期
  var time = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + '00'
  return time
}
export function getHMS() { // 获取时间
  var date = new Date()
  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()

  // 这样写显示时间在1~9会挤占空间；所以要在1~9的数字前补零;
  if (hour < 10) {
    hour = '0' + hour
  }
  if (minute < 10) {
    minute = '0' + minute
  }
  if (second < 10) {
    second = '0' + second
  }
  var x = date.getDay()// 获取星期
  var time = hour + ':' + minute + ':' + '00'
  return time
}
